package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.PotentialStudent;
import cn.wolfcode.crm.query.MovethehistoryQueryObject;
import cn.wolfcode.crm.service.IMovethehistoryService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

@Controller
@RequestMapping("movethehistory")
public class MovethehistoryController {
    @Autowired
    private IMovethehistoryService movethehistoryService;


    @RequestMapping("view")
    public String view(){
        return "movethehistory";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(MovethehistoryQueryObject qo){
        return movethehistoryService.getAll(qo);
    }

    @RequestMapping("transfer")
    @ResponseBody
    public Object transfer(Long id, String name, String qq, String tel, Employee salesman){
        JSONResult result = new JSONResult();
        try {
            PotentialStudent ps = new PotentialStudent();
            ps.setId(id);
            ps.setName(name);
            ps.setQq(qq);
            ps.setTel(tel);
            ps.setSalesman(salesman);
            movethehistoryService.saveOrUpdate(ps, null);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.remark("跟进失败");
        }
    }

    @RequestMapping("assign")
    @ResponseBody
    public Object assign(Long id, String name, String qq, String tel, Employee salesman,Long usernameId){
        JSONResult result = new JSONResult();
        try {
            PotentialStudent ps = new PotentialStudent();
            ps.setId(id);
            ps.setName(name);
            ps.setQq(qq);
            ps.setTel(tel);
            ps.setSalesman(salesman);
            movethehistoryService.saveOrUpdate(ps, usernameId);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.remark("跟进失败");
        }
    }


}
